// Copyright 2017 Baidu Inc. All Rights Reserved.
// Author: Su Hao (suhao@baidu.com)
//
// Description: The timestamp adapter.

#include "baidu_ca_timestamp.h"
#ifdef __linux__
#include <sys/time.h>
#endif
#include "baidu_ca_internal.h"

BCA_LOC_IMPL bca_timestamp_f s_bca_timestamp = NULL;

BCA_EXT_IMPL void baidu_ca_timestamp_init(bca_timestamp_f f_timestamp) {
    s_bca_timestamp = f_timestamp;
}

BCA_INT_IMPL bca_u32_t bca_timestamp() {
    bca_u32_t rs = 0;

    if (s_bca_timestamp) {
        rs = s_bca_timestamp();
    }
#ifdef __linux__
    else {
        struct timeval current;
        gettimeofday(&current, NULL);
        rs = current.tv_sec * 1000 + current.tv_usec / 1000;
    }
#endif
    return rs;
}

